package com.masterclient.app.base;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.masterclient.app.R;

/**
 * 作者：sean
 * 创建时间：2017/11/3 15:11
 * 功能说明：
 */

public class ToastDialog extends Dialog{
    private TextView tv_tag;
    String type;
    String content;
    Activity activity;
    //1勾，0叉
    public ToastDialog(@NonNull Activity context, String type, String content) {
        super(context,R.style.MyDialog2);
        this.type = type;
        this.content = content;
        activity = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_toast);
        tv_tag = (TextView) findViewById(R.id.tv_tag);
//        if("0".equals(type)){
            tv_tag.setText(content);
//        }

        tv_tag.postDelayed(new Runnable() {
            @Override
            public void run() {
                dismiss();
                if(!"0".equals(type)){
                    activity.finish();
                }
            }
        },2000 );
    }

    @Override
    public void show() {
        super.show();
    }

    @Override
    protected void onStart() {
        super.onStart();
        Window window = getWindow();
        WindowManager.LayoutParams windowparams = window.getAttributes();
        window.setGravity(Gravity.CENTER);
        window.setBackgroundDrawableResource(android.R.color.transparent);
        window.setAttributes(windowparams);
    }
}
